package com.incross.dawin.objects;

import java.util.ArrayList;

import com.incross.dawin.http.parser.AdditionalInfoParser;
import com.incross.dawin.http.parser.AdditionalInfoParser.SnsShare;
import com.incross.dawin.http.parser.AdditionalInfoParser.TickerAd;
import com.incross.dawin.http.parser.BasicInfoParser;
import com.incross.dawin.http.parser.IconInfoParser;
import com.incross.dawin.http.parser.MediaFileInfoParser;
import com.incross.dawin.http.parser.TrackingInfoParser;

public class AdInfos {
	public static final int SCREEN = 0;
	public static final int FACEBOOK = IconInfoParser.ICON_FACEBOOK;
	public static final int TWITTER = IconInfoParser.ICON_TWITTER;
	public static final int EVENT = IconInfoParser.ICON_EVENT;
	public static final int DOWNLOAD = IconInfoParser.ICON_DOWNLOAD;
	public static final int MAP = IconInfoParser.ICON_MAP;
	public static final int CALL = IconInfoParser.ICON_CALL;
	public static final int SKIP = IconInfoParser.ICON_SKIP;
	public static final int SKIP_DESCRIPTION = IconInfoParser.ICON_SKIP_DESCRIPTION;
	public static final int SNS_SHARE = IconInfoParser.ICON_SNS_SHARE;
	
	public static final int ACTION_MODE_SNS = 10000;
	public static final int ACTION_MODE_EVENT = 11000;
	public static final int ACTION_MODE_MAP = 12000;
	public static final int ACTION_MODE_DOWNLOAD = 13000;
	public static final int ACTION_MODE_CALL = 14000;
	// 20130930 액션버튼이 없는 경우도 있다고 하여 ACTION_MODE_NONE 추가함.
	public static final int ACTION_MODE_NONE = 15000;
	
	// 브라우저 분기에 사용될 상수 정의
	public static final String BROWSER_MODE_CLICKVIEWER = "0"; // 클릭뷰어.
	public static final String BROWSER_MODE_DEFAULT_BROWSER = "1"; // 단말 내장 브라우저.
	
	private BasicInfoParser mBasicInfo;
	private TrackingInfoParser mTrackingInfo;
	private MediaFileInfoParser mMediaFileInfo;
	private IconInfoParser mIconInfo;
	private AdditionalInfoParser mAddInfo;
	
	public AdInfos(BasicInfoParser basicInfo, TrackingInfoParser trackingInfo, MediaFileInfoParser mediaFileInfo, IconInfoParser iconInfo, AdditionalInfoParser addInfo) {
		mBasicInfo = basicInfo;
		mTrackingInfo = trackingInfo;
		mMediaFileInfo = mediaFileInfo;
		mIconInfo = iconInfo;
		mAddInfo = addInfo;
	}
	
	/*public int getActionMode() {
		
	}*/
	
	public boolean isParsingProblemOccured() {
		if(mBasicInfo != null) {
			if(mBasicInfo.getAdId().equals("-1")) return false;
		}
		
		// 1. 각각의 정보가 null이면 문제로 판단함.
		if(mBasicInfo == null || mTrackingInfo == null || mMediaFileInfo == null || mIconInfo == null) return true;
		// 2. 각각의 정보에서 AdditionalInfo를 제외한 파서중 한군데라도 문제가 isParsingProblemOccured가 true이면 문제로 판단함.
		if(mBasicInfo.isParsingProblemOccured() || mTrackingInfo.isParsingProblemOccured() || mMediaFileInfo.isParsingProblemOccured() || mIconInfo.isParsingProblemOccured()) return true;
		
		return false;
	}
	
	// get basic informations
	public String getAdSystem() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getAdSystem();
	}
	
	public String getAdId() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getAdId();
	}
	
	public String getAdTitle() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getAdTitle();
	}
	
	public String getAdDescription() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getAdDescription();
	}
	
	public String getErrorUrl() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getErrorUrl();
	}
	
	public String getAdDuration() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getAdDuration();
	}
	
	public String getVideoclickThrough() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getVideoClickThrough();
	}
	
	public String getVideoClickTracking() {
		if(mBasicInfo == null) return "";
		return mBasicInfo.getVideoClickTracking();
	}
	
	public int getActionMode() {
		if(mIconInfo == null) return -1;
		return mIconInfo.getActionButtonMode();
	}
	
	public String getBrowserMode() {
		if(mBasicInfo == null) return AdInfos.BROWSER_MODE_DEFAULT_BROWSER;
		// 브라우저 분기 추가
		return mBasicInfo.getBrowserMode();
	}
	
	// get media file informations
	public String getMediaFileUrl() {
		if(mMediaFileInfo == null) return "";
		return mMediaFileInfo.getMediaFileUrl();
	}
	
	public String getMediaDelivery() {
		if(mMediaFileInfo == null) return "";
		return mMediaFileInfo.getMediaDelivery();
	}
	
	public String getMediaType() {
		if(mMediaFileInfo == null) return "";
		return mMediaFileInfo.getMediaType();
	}
	
	public int getMediaBitrate() {
		if(mMediaFileInfo == null) return -1;
		return mMediaFileInfo.getMediaBitrate();
	}
	
	public int getMediaWidth() {
		if(mMediaFileInfo == null) return -1;
		return mMediaFileInfo.getMediaWidth();
	}
	
	public int getMediaHeight() {
		if(mMediaFileInfo == null) return -1;
		return mMediaFileInfo.getMediaHeight();
	}
	
	public String getMediaThumbnailUrl() {
		if(mMediaFileInfo == null) return "";
		return mMediaFileInfo.getMediaThumbnailUrl();
	}
	
	// get Tracking informations
	
	public String getStartTag() {
		if(mTrackingInfo == null) return "";
		return mTrackingInfo.getStartTag();
	}
	
	public String getQuarterTag(int quarter) {
		if(mTrackingInfo == null) return "";
		return mTrackingInfo.getQuarterTag(quarter);
	}
	
	public int getQuarterTime(int quarter) {
		if(mTrackingInfo == null) return -1;
		return mTrackingInfo.getQuarterTime(quarter);
	}
	
	public String getEndTag() {
		if(mTrackingInfo == null) return "";
		return mTrackingInfo.getEndTag();
	}
	
	public String getSkipTag() {
		if(mTrackingInfo == null) return "";
		return mTrackingInfo.getSkipTag();
	}
	
	public String getChargeTag() {
		if(mTrackingInfo == null) return "";
		return mTrackingInfo.getChargeTag();
	}
	
	public int getChargeTime() {
		if(mTrackingInfo == null) return -1;
		return mTrackingInfo.getChargeTime();
	}
	
	// get icons information
	public boolean isAvailable(int which) {
		if(mIconInfo == null) return false;
		return mIconInfo.isAvailable(which);
	}
	
	public String getIconUrl(int which) {
		if(mIconInfo == null) return "";
		return mIconInfo.getIconUrl(which);
	}
	
	public String getClickThrough(int which) {
		if(mIconInfo == null) return "";
		return mIconInfo.getClickThrough(which);
	}
	
	public String getTrackingUrl(int which) {
		if(mIconInfo == null) return "";
		return mIconInfo.getTrackingUrl(which);
	}
	
	public int getIconShowTime(int which) {
		if(mIconInfo == null) return -1;
		return mIconInfo.getIconShowTime(which);
	}
	
	public boolean isIconShowDirectly(int which) {
		if(mIconInfo == null) return false;
		return mIconInfo.isIconShowDirectly(which);
	}
	
	// get additional informations
	public boolean isAdditionalInfoAvailable() {
		if(mAddInfo == null) return false;
		return mAddInfo.isAdditionalInfoAvailable();
	}
	
	public boolean isTickerAvailable() {
		if(mAddInfo == null) return false;
		if(mAddInfo.isAdditionalInfoAvailable()) {
			return mAddInfo.isTickerAvailable();
		}
		
		return false;
	}
	
	public boolean isSnsShareAvailable() {
		if(mAddInfo == null) return false;
		if(mAddInfo.isAdditionalInfoAvailable()) {
			return mAddInfo.isSnsShareAvailable();
		}
		
		return false;
	}
	
	public ArrayList<SnsShare> getSnsShareList() {
		if(mAddInfo == null) return null;
		if(mAddInfo.isAdditionalInfoAvailable() && mAddInfo.isSnsShareAvailable()) {
			return mAddInfo.getSnsShareList();
		}
		
		return null;
	}
	
	public ArrayList<TickerAd> getTickerList() {
		if(mAddInfo == null) return null;
		if(mAddInfo.isAdditionalInfoAvailable() && mAddInfo.isTickerAvailable()) {
			return mAddInfo.getTickerAdList();
		}
		
		return null;
	}
}
